@echo off
echo.
echo ==============================================
echo   YanXue AI Go 知识百科Agent测试
echo ==============================================
echo.

REM 设置环境变量
echo 正在设置配置环境变量...
set APP_NAME=example-service
set APP_VERSION=1.0.0
set APP_ENVIRONMENT=development
set SERVER_HOST=0.0.0.0
set SERVER_PORT=8081
set DATABASE_HOST=127.0.0.1
set DATABASE_PORT=3306
set DATABASE_USER=root
set DATABASE_PASSWORD=password
set DATABASE_NAME=yanxue_ai
set REDIS_HOST=127.0.0.1
set REDIS_PORT=6379
set REDIS_PASSWORD=redis_password
set AI_OPENAI_API_KEY=your_api_key_here
set AI_OPENAI_BASE_URL=https://api.example.com
set AI_OPENAI_MODEL=gpt-3.5-turbo
set LOG_LEVEL=info
set JWT_SECRET=knowledge-agent-jwt-secret-key

echo ✓ 环境变量设置完成
echo.

echo 知识百科Agent功能演示:
echo   - 🧠 智能问答：支持多领域知识问答
echo   - 📚 分类管理：自动分类问题和答案
echo   - 🎯 难度评估：自动评估问题难度
echo   - 📊 数据分析：问答统计和质量分析
echo   - ⭐ 用户反馈：支持评分和反馈收集
echo   - 🌍 多语言：支持中英文问答
echo.

echo 检查Go环境...
go version >nul 2>&1
if %errorlevel% neq 0 (
    echo ✗ 错误: Go未安装或不在PATH中
    pause
    exit /b 1
)
echo ✓ Go环境正常

echo.
echo 更新依赖...
cd services\agent
go mod tidy
if %errorlevel% neq 0 (
    echo ✗ 错误: 依赖更新失败
    cd ..\..
    pause
    exit /b 1
)
cd ..\..
echo ✓ 依赖更新完成

echo.
echo ==============================================
echo   选择测试模式
echo ==============================================
echo.
echo 1. 启动Agent服务（包含知识百科功能）
echo 2. 查看API文档和测试用例
echo 3. 生成示例请求和响应
echo.
set /p choice="请选择 (1-3): "

if "%choice%"=="1" (
    echo.
    echo 正在启动Agent服务...
    echo 服务将在 http://localhost:%SERVER_PORT% 启动
    echo.
    echo 🧠 知识百科Agent API端点:
    echo.
    echo 📋 基础功能:
    echo   创建知识Agent: POST /api/v1/knowledge/agents
    echo   获取Agent信息: GET  /api/v1/knowledge/agents/{id}
    echo   获取分析数据:   GET  /api/v1/knowledge/agents/{id}/analytics
    echo.
    echo 💬 问答功能:
    echo   快速提问:     POST /api/v1/knowledge/agents/{id}/ask
    echo   开始会话:     POST /api/v1/knowledge/agents/{id}/session
    echo   会话提问:     POST /api/v1/knowledge/ask
    echo   问答历史:     GET  /api/v1/knowledge/history
    echo   评分反馈:     POST /api/v1/knowledge/rate
    echo.
    echo 🔧 辅助功能:
    echo   知识分类:     GET  /api/v1/knowledge/categories
    echo   热门问题:     GET  /api/v1/knowledge/agents/{id}/popular
    echo.
    echo 正在启动服务...
    cd services\agent
    go run cmd\main.go
) else if "%choice%"=="2" (
    echo.
    echo ==============================================
    echo   知识百科Agent API 文档
    echo ==============================================
    echo.
    echo 🎯 1. 创建知识百科Agent
    echo POST /api/v1/knowledge/agents
    echo Content-Type: application/json
    echo.
    echo 请求示例:
    echo {
    echo   "name": "科技百科助手",
    echo   "description": "专注于科学技术领域的知识问答",
    echo   "model": "gpt-3.5-turbo",
    echo   "categories": ["科学技术", "工程", "计算机"],
    echo   "languages": ["中文", "英文"],
    echo   "difficulty": "medium",
    echo   "response_style": "detailed",
    echo   "temperature": 0.7,
    echo   "max_tokens": 2000,
    echo   "created_by": 1
    echo }
    echo.
    echo 🤖 2. 快速提问 ^(无需会话^)
    echo POST /api/v1/knowledge/agents/{agent_id}/ask
    echo.
    echo 请求示例:
    echo {
    echo   "question": "什么是人工智能？",
    echo   "language": "中文"
    echo }
    echo.
    echo 📚 3. 获取知识分类
    echo GET /api/v1/knowledge/categories
    echo.
    echo 📊 4. 获取分析数据
    echo GET /api/v1/knowledge/agents/{agent_id}/analytics?days=7
    echo.
    echo ⭐ 5. 评分反馈
    echo POST /api/v1/knowledge/rate
    echo {
    echo   "question_id": 1,
    echo   "rating": 5,
    echo   "feedback": "回答很有帮助",
    echo   "is_helpful": true
    echo }
    echo.
) else if "%choice%"=="3" (
    echo.
    echo ==============================================
    echo   生成测试用例
    echo ==============================================
    echo.
    echo 正在生成知识百科Agent测试脚本...
    
    echo # 知识百科Agent测试脚本 > knowledge_test.sh
    echo. >> knowledge_test.sh
    echo # 1. 创建知识Agent >> knowledge_test.sh
    echo curl -X POST http://localhost:8081/api/v1/knowledge/agents \ >> knowledge_test.sh
    echo   -H "Content-Type: application/json" \ >> knowledge_test.sh
    echo   -d '{' >> knowledge_test.sh
    echo     "name": "通用知识百科", >> knowledge_test.sh
    echo     "description": "覆盖各领域的通用知识问答助手", >> knowledge_test.sh
    echo     "model": "gpt-3.5-turbo", >> knowledge_test.sh
    echo     "categories": ["科学技术", "历史人文", "地理自然"], >> knowledge_test.sh
    echo     "languages": ["中文"], >> knowledge_test.sh
    echo     "difficulty": "medium", >> knowledge_test.sh
    echo     "response_style": "detailed", >> knowledge_test.sh
    echo     "temperature": 0.7, >> knowledge_test.sh
    echo     "max_tokens": 2000, >> knowledge_test.sh
    echo     "created_by": 1 >> knowledge_test.sh
    echo   }' >> knowledge_test.sh
    echo. >> knowledge_test.sh
    echo # 2. 快速提问测试 >> knowledge_test.sh
    echo curl -X POST http://localhost:8081/api/v1/knowledge/agents/1/ask \ >> knowledge_test.sh
    echo   -H "Content-Type: application/json" \ >> knowledge_test.sh
    echo   -d '{' >> knowledge_test.sh
    echo     "question": "地球的年龄大概是多少？", >> knowledge_test.sh
    echo     "language": "中文" >> knowledge_test.sh
    echo   }' >> knowledge_test.sh
    echo. >> knowledge_test.sh
    echo # 3. 获取知识分类 >> knowledge_test.sh
    echo curl http://localhost:8081/api/v1/knowledge/categories >> knowledge_test.sh
    echo. >> knowledge_test.sh
    echo # 4. 获取分析数据 >> knowledge_test.sh
    echo curl http://localhost:8081/api/v1/knowledge/agents/1/analytics?days=7 >> knowledge_test.sh
    
    echo ✓ 测试脚本已生成: knowledge_test.sh
    echo.
    echo 🧪 示例问题:
    echo   - "什么是人工智能？"
    echo   - "地球有多少年历史？"
    echo   - "如何保持健康的生活方式？"
    echo   - "什么是区块链技术？"
    echo   - "中国有多少个省份？"
    echo   - "太阳系有几大行星？"
    echo   - "什么是光合作用？"
    echo   - "世界最高的山峰是什么？"
    echo.
    echo 📊 功能特色:
    echo   ✓ 自动分类问题（科学技术、历史人文、地理自然等）
    echo   ✓ 智能难度评估（easy, medium, hard, expert）
    echo   ✓ 置信度计算（基于答案质量和复杂度）
    echo   ✓ 响应时间统计
    echo   ✓ Token使用量统计
    echo   ✓ 用户评分和反馈收集
    echo   ✓ 相关话题推荐
    echo   ✓ 学习建议生成
) else (
    echo 无效选择，退出。
)

echo.
pause